package com.lx.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import weixin.popular.util.SignatureUtil;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author lixing
 * @date 2021/5/24 19:46
 */
@Data
@Component
public class WxConfig {

    @Value("${weixin.appID}")
    private String appID;
    @Value("${weixin.appsecret}")
    private String appsecret;
    @Value("${weixin.appDomain}")
    private String appDomain;
    @Value("${weixin.token}")
    private String token;

    public String getTokenString() {
        return token;
    }


    public static String getMD5Str(String str) {
        byte[] digest = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            digest  = md5.digest(str.getBytes("utf-8"));
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //16是表示转换为16进制数
        String md5Str = new BigInteger(1, digest).toString(16);
        return md5Str;
    }

    public static void main(String[] args) {
        String signature = SignatureUtil.generateEventMessageSignature("lixing", "adw", "123");

    }

}
